import subprocess
import sys


def run_pytest():
    node = 2
    if node == 1:
        command = [sys.executable, "-m", "pytest","-vs","--alluredir=./allure-results","project_root/tests/test_cookie_login.py","project_root/tests/test_personal.py","project_root/tests/test_home.py",
                "project_root/tests/test_site.py","project_root/tests/test_monitoring.py","project_root/tests/test_history.py","project_root/tests/test_alarm.py","project_root/tests/test_report.py",
                "project_root/tests/test_alarmset.py","project_root/tests/test_textalarmset.py","project_root/tests/test_userlist.py","project_root/tests/test_operation_role.py",
                "project_root/tests/test_data_role.py","project_root/tests/test_log.py"]
    else:
        command = [sys.executable, "-m", "pytest","-vs","project_root/tests/test_cookie_login.py","project_root/tests/test_personal.py","project_root/tests/test_home.py"]
    # 使用 subprocess 运行 pytest 命令
    result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
    # 输出 pytest 的执行结果
    print("=== 测试输出 ===")
    print(result.stdout)
    if result.stderr:
        print("\n=== 错误信息 ===")
        print(result.stderr)
    


# 网页显示测试结果
# allure serve ./allure-results  

if __name__ == '__main__':
    run_pytest()
    # run_allure()
     